import java.util.Scanner;

public class Day_4_2_进制转换 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()) {
            int m = scan.nextInt();
            int n = scan.nextInt();
            String table = "0123456789ABCDEF";
            StringBuilder s = new StringBuilder();
            boolean flg = false;
            if(m < 0) {
                m = -m;
                flg = true;
            }

            while (m != 0) {
                s.append(m % n);
                m /= n;
            }
            if(flg) {
                s.append("-");
            }

            s.reverse();

            System.out.println(s.toString());
        }
    }

}
